package file;

import java.io.*;


public class FileSearch{
	public void FileT(String dir)throws Exception{
		File d = null;
		
		try {
			d=new File(dir);
			
		    if (d.isDirectory()) {
		        System.out.println("검색 디렉토리 " + dir);
		        System.out.println("=============================");
		        
		        String list[] = d.list();
		        for (int i=0; i < list.length; i++) {
		          File f = new File(dir + "/" + list[i]);
		          if (f.isDirectory()) {
		            System.out.println(list[i] + " : 디렉토리");
		            
		            //하위디렉토리검색
			            String dept =dir + "/" + list[i];	
			            File cc = new File(dept);
			            String dd[]=cc.list();			            
			            for(int p=0;p<dd.length; p++){
			            	File v = new File(dept + "/"+dd[p]);
			            	if(v.isFile()){
			            		System.out.println("-"+dept + "/"+dd[p]+ ": 파일");
			            	}else{
			            		System.out.println("-"+dept + "/"+dd[p]+ ": 디렉토리");
			            	}
			            }			            
		          } else {
		            System.out.println(list[i] + " : 파일");		            
		          }
		        }
		      } else {
		        System.out.println("지정한 " + dir + " 는 디렉토리가 아님");
		      }			
		}catch (Exception e) {
			throw e;
		}
	}
		
	public static void main(String args[]){		
		FileSearch c= new FileSearch();
		try {
			c.FileT("test");			 
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	
}
